﻿using System;
using System.Threading.Tasks;
using Hn.Database.DAL;
using Microsoft.Extensions.Logging;
using MSocketCore.Hub;
using SuperSocket;
using SuperSocket.Command;

namespace MSocketCore.MSocket
{
    [MyCmdFilter]
    [Command(Key = "01")]
    public class AFN01: IAsyncCommand<MySession,MyPackage>
    {
        private readonly ILogger<AFN01> _logger;

        public AFN01(ILogger<AFN01> logger)
        {
            _logger = logger;
        }

        private readonly MessageClient _client;

        public AFN01(MessageClient client)
        {
            _client = client;
        }

        public ValueTask ExecuteAsync(MySession session, MyPackage info)
        {
            _logger.LogInformation($"App Recevice:{info.Sn}[Confirm]\n{info.Message}");

            _client.SendMessage("aa", "ddd");
            var name = UserDAL.GetUserIdBySn(info.Sn);
            switch (info._Fn)
            {
                case 1:
                    _client.SendMessage(name, info.Sn + "Success" + "\n");
                    break;
                case 2:
                    _client.SendMessage(name, info.Sn + "Fail" + "\n");
                    break;
            }

            return new ValueTask();
        }
    }
}
